package test.myorm.chain;

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class Invocation {
	
	private Object target;
	private Method method;
	private Object[] args;
	private Map<String, Object> attrs = new HashMap<>();
	private Object[] realArgs;
	public Object getTarget() {
		return target;
	}
	public void setTarget(Object target) {
		this.target = target;
	}
	public Method getMethod() {
		return method;
	}
	public void setMethod(Method method) {
		this.method = method;
	}
	public Object[] getArgs() {
		return args;
	}
	public void setArgs(Object[] args) {
		this.args = args;
	}
	public void attr(String key, Object obj) {
		this.attrs.put(key, obj);
	}
	public Object attr(String key) {
		return this.attrs.get(key);
	}
	public Object[] getRealArgs() {
		return realArgs;
	}
	public void setRealArgs(Object[] realArgs) {
		this.realArgs = realArgs;
	}
	public Object invoke() {
		try {
			return method.invoke(target, args);
		} catch (Exception e) {
			throw new RuntimeException(e.getMessage());
		}
	}
	@Override
	public String toString() {
		return "Invocation [target=" + target + ", method=" + method + ", args=" + Arrays.toString(args) + "]";
	}

}
